from unicorn.signal import RegisteredSignals, Signal

class IMSignal(Signal):
    def __init__(self, accountId=None, contactId=None, **kwargs):
        super(IMSignal, self).__init__(**kwargs)
        assert accountId or contactId
        if accountId:
            self.accountId = accountId
        if contactId:
            self.contactId = contactId

class SetGroup(IMSignal):
    signalName = "apps.im.SetGroup"
    def __init__(self, group, accountId=None, contactId=None, **kwargs):
        super(SetGroup, self).__init__(accountId, contactId, **kwargs)
        self.group = group
RegisteredSignals.register(SetGroup)

class SetConversation(IMSignal):
    signalName = "apps.im.SetConversation"
RegisteredSignals.register(SetConversation)

class EnterConversation(IMSignal):
    signalName = "apps.im.conversation.EnterConversation"
    def __init__(self, conversationId, accountId=None, contactId=None, **kwargs):
        super(EnterConversation, self).__init__(accountId, contactId, **kwargs)
        self.conversationId = conversationId
RegisteredSignals.register(EnterConversation)

class LeaveConversation(EnterConversation):
    signalName = "apps.im.conversation.LeaveConversation"
RegisteredSignals.register(LeaveConversation)

class LogConversation(IMSignal):
    signalName = "apps.im.conversation.LogConversation"
    def __init__(self, conversationId, message, accountId=None, contactId=None, **kwargs):
        super(LogConversation, self).__init__(accountId, contactId, **kwargs)
        self.conversationId = conversationId
        self.message = message
RegisteredSignals.register(LogConversation)

class SetStatus(IMSignal):
    signalName = "apps.im.SetStatus"
    def __init__(self, isOnline, accountId=None, contactId=None, **kwargs):
        super(SetStatus, self).__init__(accountId, contactId, **kwargs)
        self.isOnline = isOnline
RegisteredSignals.register(SetStatus)

class SetBuddyListStatus(IMSignal):
    signalName = "apps.im.SetBuddyListStatus"
    def __init__(self, onlineContacts, accountId, **kwargs):
        super(SetBuddyListStatus, self).__init__(accountId, contactId=None, **kwargs)
        self.onlineContacts = onlineContacts
RegisteredSignals.register(SetBuddyListStatus)

class SetAvatar(IMSignal):
    signalName = "apps.im.SetAvatar"
    def __init__(self, imagePath, accountId=None, contactId=None, **kwargs):
        super(SetAvatar, self).__init__(accountId, contactId, **kwargs)
        self.imagePath = imagePath
RegisteredSignals.register(SetAvatar)

class FindAccount(IMSignal):
    signalName = "apps.im.FindAccount"
    def __init__(self, accountId, **kwargs):
        super(FindAccount, self).__init__(accountId, contactId=None, **kwargs)
RegisteredSignals.register(FindAccount)

class NewAccount(IMSignal):
    signalName = "apps.im.NewAccount"
    def __init__(self, buddies, accountId, **kwargs):
        super(NewAccount, self).__init__(accountId, contactId=None, **kwargs)
        self.buddies = buddies
RegisteredSignals.register(NewAccount)

class AccountSignal(Signal):
    signalName = "apps.im.AccountSignal"
    def __init__(self, accountBlocked, accountExists, **kwargs):
        super(AccountSignal, self).__init__(**kwargs)
        self.accountBlocked = accountBlocked
        self.accountExists = accountExists
RegisteredSignals.register(AccountSignal)

class SetNickName(IMSignal):
    signalName = "apps.im.SetNickName"
    def __init__(self, nickName, accountId=None, contactId=None, **kwargs):
        super(SetNickName, self).__init__(accountId, contactId, **kwargs)
        self.nickName = nickName
RegisteredSignals.register(SetNickName)

class SetPersonalMessage(IMSignal):
    signalName = "apps.im.SetPersonalMessage"
    def __init__(self, personalMessage, accountId=None, contactId=None, **kwargs):
        super(SetPersonalMessage, self).__init__(accountId, contactId, **kwargs)
        self.personalMessage = personalMessage
RegisteredSignals.register(SetPersonalMessage)

class IsAccountAllowed(IMSignal):
    signalName = "apps.im.IsAccountAllowed"
    def __init__(self, accountId, **kwargs):
        super(IsAccountAllowed, self).__init__(accountId, contactId=None, **kwargs)
RegisteredSignals.register(IsAccountAllowed)

class IsContactAllowed(IMSignal):
    signalName = "apps.im.IsContactAllowed"
RegisteredSignals.register(IsContactAllowed)

class AddContact(IMSignal):
    signalName = "apps.im.AddContact"
    def __init__(self, group, accountId=None, contactId=None, **kwargs):
        super(AddContact, self).__init__(accountId, contactId, **kwargs)
        self.group = group
RegisteredSignals.register(AddContact)

class RemoveContact(IMSignal):
    signalName = "apps.im.RemoveContact"
RegisteredSignals.register(RemoveContact)

class SetFileTransfer(IMSignal):
    signalName = "apps.im.SetFileTransfer"
RegisteredSignals.register(SetFileTransfer)

class IsFileTransferAllowed(IMSignal):
    signalName = "apps.im.IsFileTransferAllowed"
RegisteredSignals.register(IsFileTransferAllowed)

class LogFileTransfer(IMSignal):
    signalName = "apps.im.conversation.LogFileTransfer"
    def __init__(self, conversationId, remoteFileName, localPath, accountId=None, contactId=None, **kwargs):
        super(LogFileTransfer, self).__init__(accountId, contactId, **kwargs)
        self.conversationId = conversationId
        self.remoteFileName = remoteFileName
        self.localPath = localPath
RegisteredSignals.register(LogFileTransfer)

class LogMessage(IMSignal):
    signalName = "apps.im.LogMessage"
    def __init__(self, accountIP, contactIP, message, isSender, accountId=None, contactId=None, **kwargs):
        super(LogMessage, self).__init__(accountId, contactId, **kwargs)
        self.accountIP = accountIP
        self.contactIP = contactIP
        self.message = message
        self.isSender = isSender
RegisteredSignals.register(LogMessage)

class Disconnect(IMSignal):
    signalName = "apps.im.Disconnect"
    def __init__(self, accountId, **kwargs):
        super(Disconnect, self).__init__(accountId, contactId=None, **kwargs)
RegisteredSignals.register(Disconnect)

